package com.yanqu.road.server.gameplayer.module.activity.seacraft;

import com.yanqu.road.entity.activity.seacraft.pirateriot.SeacraftPirateRiotBattlePatrons;
import com.yanqu.road.entity.activity.seacraft.pirateriot.SeacraftPirateRiotChange;
import com.yanqu.road.entity.activity.seacraft.pirateriot.SeacraftPirateRiotMonsterData;
import com.yanqu.road.entity.activity.seacraft.pirateriot.eliminate.SeacraftPirateRiotBoom;
import com.yanqu.road.entity.activity.seacraft.pirateriot.eliminate.SeacraftPirateRiotEliminateResult;
import com.yanqu.road.entity.activity.seacraft.pirateriot.eliminate.SeacraftPirateRiotEliminateRoundResult;
import com.yanqu.road.entity.activity.seacraft.pirateriot.eliminate.SeacraftPirateRiotEliminateStageResult;
import com.yanqu.road.pb.activity.SeacraftPirateRiotProto;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
 * 没办法日志那么恶心人
 */
public class SeacraftPirateRiotLogHelper {

    public static String parsePatronsMaxHp(Map<Integer, SeacraftPirateRiotBattlePatrons> battlePatronsMap) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Integer, SeacraftPirateRiotBattlePatrons> entry : battlePatronsMap.entrySet()) {
            sb.append(entry.getKey());
            sb.append("=");
            sb.append(entry.getValue().getHpMax());
            sb.append(";");
        }
        return sb.toString();
    }

    public static String parsePatronsCurHp(Map<Integer, SeacraftPirateRiotBattlePatrons> battlePatronsMap) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Integer, SeacraftPirateRiotBattlePatrons> entry : battlePatronsMap.entrySet()) {
            sb.append(entry.getKey());
            sb.append("=");
            sb.append(entry.getValue().getHp());
            sb.append(";");
        }
        return sb.toString();
    }

    public static String parsePatronsAtk(Map<Integer, SeacraftPirateRiotBattlePatrons> battlePatronsMap) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Integer, SeacraftPirateRiotBattlePatrons> entry : battlePatronsMap.entrySet()) {
            sb.append(entry.getKey());
            sb.append("=");
            sb.append(entry.getValue().getAtk());
            sb.append(";");
        }
        return sb.toString();
    }

    public static String parseMonsterCurHp(List<SeacraftPirateRiotMonsterData> monsterDataList) {
        StringBuilder sb = new StringBuilder();
        for (SeacraftPirateRiotMonsterData monsterData : monsterDataList) {
            sb.append(monsterData.getId());
            sb.append("=");
            sb.append(monsterData.getHp());
            sb.append(";");
        }
        return sb.toString();
    }

    public static int parseFirstRoundEliminateCount(SeacraftPirateRiotEliminateResult eliminateResult) {
        int count = 0;
        if (!eliminateResult.getRoundResultList().isEmpty()) {
            SeacraftPirateRiotEliminateRoundResult roundResult = eliminateResult.getRoundResultList().get(0);
            for (SeacraftPirateRiotEliminateStageResult stageResult : roundResult.getStageResultList()) {
                count += stageResult.getBlockList().size();
            }
        }
        return count;
    }

    public static String parseFirstRoundBoomUse(SeacraftPirateRiotEliminateResult eliminateResult) {
        Property property = new Property();
        if (!eliminateResult.getRoundResultList().isEmpty()) {
            SeacraftPirateRiotEliminateRoundResult roundResult = eliminateResult.getRoundResultList().get(0);
            for (SeacraftPirateRiotEliminateStageResult stageResult : roundResult.getStageResultList()) {
                for (SeacraftPirateRiotBoom boom : stageResult.getBoomList()) {
                    property.addProperty(boom.getType(), BigInteger.ONE);
                }
            }
        }
        return PropertyHelper.parsePropertyToString(property);
    }

    public static long parseFirstRoundDamage(List<SeacraftPirateRiotProto.SeacraftPirateRiotEliminateRoundMsg> roundMsgList) {
        long damage = 0L;
        if (!roundMsgList.isEmpty()) {
            SeacraftPirateRiotProto.SeacraftPirateRiotEliminateRoundMsg roundMsg = roundMsgList.get(0);
            for (SeacraftPirateRiotProto.SeacraftPirateBlockMsg blockMsg : roundMsg.getBlockMsgListList()) {
                for (SeacraftPirateRiotProto.SeacraftPirateRiotChangeMsg changeMsg : blockMsg.getChangeListList()) {
                    damage += changeMsg.getAddHp();
                }
            }
        }
        return damage * -1;
    }

    public static int parseOtherRoundEliminateCount(SeacraftPirateRiotEliminateResult eliminateResult) {
        int count = 0;
        if (!eliminateResult.getRoundResultList().isEmpty()) {
            List<SeacraftPirateRiotEliminateRoundResult> roundResultList = eliminateResult.getRoundResultList();
            for (int i = 1; i < roundResultList.size(); i++) {
                for (SeacraftPirateRiotEliminateStageResult stageResult : roundResultList.get(i).getStageResultList()) {
                    count += stageResult.getBlockList().size();
                }
            }
        }
        return count;
    }

    public static long parseOtherRoundDamage(List<SeacraftPirateRiotProto.SeacraftPirateRiotEliminateRoundMsg> roundMsgList) {
        long damage = 0L;
        if (!roundMsgList.isEmpty()) {
            for (int i = 1; i < roundMsgList.size(); i++) {
                SeacraftPirateRiotProto.SeacraftPirateRiotEliminateRoundMsg roundMsg = roundMsgList.get(i);
                for (SeacraftPirateRiotProto.SeacraftPirateBlockMsg blockMsg : roundMsg.getBlockMsgListList()) {
                    for (SeacraftPirateRiotProto.SeacraftPirateRiotChangeMsg changeMsg : blockMsg.getChangeListList()) {
                        damage += changeMsg.getAddHp();
                    }
                }

            }
        }
        return damage * -1;
    }

    public static long parseSkillDamage(List<SeacraftPirateRiotChange> changeList) {
        long damage = 0L;
        for (SeacraftPirateRiotChange change : changeList) {
            if (change.getAddHp() != null) {
                damage += change.getAddHp();
            }
        }
        return damage * -1;
    }
}
